<?php

namespace common\widgets\ajaxbtn;

use yii\base\Widget;
use yii\web\NotFoundHttpException;

/**
 * @example
 * <a href="javascript:<?= OpenBox::widget(['url'=>Url::to(['article/delete']),'width'=>'50%','height'=>'30%']) ?>" target="_self">打开弹窗1</a>
 * <a href="javascript:<?= OpenBox::widget(['url'=>Url::to(['article/delete']),'width'=>'600px','height'=>'30%','title'=>'新增案例']) ?>" target="_self">打开弹窗2</a>
 */
class OpenBox extends Widget{
    
    public $url;
    public $width;
    public $height;
    public $title = '信息';
    
    public function init(){
        parent::init();
        if(empty($this->url)){
            throw new NotFoundHttpException('url参数必须');
        }
        if(empty($this->width)){
            throw new NotFoundHttpException('width参数必须');
        }
        if(empty($this->height)){
            throw new NotFoundHttpException('height参数必须');
        }
        AjaxAsset::register($this->view);
    }
    
    public function run(){
        $str = "openBox('".$this->url."', '".$this->width."', '".$this->height."','".$this->title."')";
        return $str;
    }
    

}